package com.asman.vr.network

import com.asman.vr.utils.L
import okhttp3.Headers
import okhttp3.Interceptor
import okhttp3.Request
import okhttp3.Response
import java.io.IOException

// todo 请求头公共参数，拿不到的都全部先写死 或者先不添加

/**
 * Created by ybk on 2018/2/26.
 * 请求头拦截器
 */
class RequestHeaderInterceptor : Interceptor {
    @Throws(IOException::class)
    override fun intercept(chain: Interceptor.Chain): Response {

        // val userId = sp.getLong(SP_USER_ID, 0)
        val userId = 0

        // val prefixKey = sp.getString(SP_Domain_Prefix_Key_Prefix, "") + userId.toString()
        val prefixKey = ""

        val request = chain.request()
        val authorised: Request
        val headers =
            Headers.Builder()
                // .add("x-access-token", sp.getString(SP_LOGIN_TOKEN, "")!!) // 用户登录凭据

                //应用类型:1-点点搭微信小程序,2-AIC平台,3-设计师平台,4-牛牛搭app
                // .add("x-application-type", MyApplication.context.getString(R.string.config_application_type))

                // .add("x-application-os", "android")
                // .add("x-application-version", BuildConfig.VERSION_NAME.replace("-dev", "")) //应用版本
                // .add("x-tenant-prefix", sp.getString(prefixKey, "")) //租户域名
                .build()
        authorised = request.newBuilder().headers(headers).build()
        // L.i("APII::--> x-access-token  ${sp.getString(SP_LOGIN_TOKEN, "")!!}")
        return chain.proceed(authorised)
    }
}
